package com.da.javatest.niuke.jianzhi;

import java.util.LinkedHashMap;
import java.util.Map;

import com.da.javatest.niuke.common.ListNode;

/**
 * @author chenlida
 * @date 2020/10/26 14:44
 * https://www.nowcoder.com/practice/fc533c45b73a41b0b44ccba763f866ef?
 * tpId=13&tags=&title=&diffculty=0&judgeStatus=0&rp=1
 */
public class C56Solution {
    public ListNode deleteDuplication(ListNode pHead) {
        Map<Integer, Integer> map = new LinkedHashMap<>();
        ListNode node = pHead;
        while (node != null) {
            map.merge(node.val, 1, Integer::sum);
            node = node.next;
        }
        ListNode listNode = new ListNode(-1);
        listNode.next = pHead;
        pHead = listNode;
        node = pHead;
        for (Integer key : map.keySet()) {
            if (map.get(key) == 1) {
                node = node.next;
                node.val = key;
            }
        }
        node.next = null;
        return pHead.next;
    }
}
